package dryven.view.engine.expression;

import dryven.codegen.asm.MethodBuilder;
import dryven.codegen.asm.TempValue;
import dryven.reflection.TypeRef;
import dryven.view.ViewDataDictionary;
import dryven.view.engine.expression.nodelisters.NodeLister;
import dryven.view.engine.expression.nodetypes.AbstractExpressionNode;

public class ViewDataDeclaration extends AbstractExpressionNode {
	private TypeRef type;
	private String name;
	
	public ViewDataDeclaration(TypeRef type, String name, NodeLister lister) {
		super(lister);
		this.type = type;
		this.name = name;
	}

	@Override
	public TypeRef getType() {
		return type;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public boolean allowsWildChar() {
		return false;
	}

	@Override
	public TypeRef getComponentType() {
		return null;
	}

	@Override
	public Object evaluate(Object value) {
		if(value instanceof ViewDataDictionary) {
			ViewDataDictionary viewData = (ViewDataDictionary)value;
			return viewData.getRootValue(name);
		} else {
			throw new RuntimeException();
		}
	}

	@Override
	public TempValue writeInstructions(MethodBuilder builder, TempValue value) {
		return null;
	}	
}
